package com.cndw.kungfu.model.activity.domain;

import java.util.HashMap;
import java.util.List;
import java.util.Map;

import com.cndw.kungfu.config.ConstantsConfig;
import com.cndw.kungfu.ext.LogUtil;
import com.cndw.kungfu.ext.StringProcesser;
import com.cndw.kungfu.ext.XmlProcesser;

/**
 * 宝箱开启的配置实体类
 * @author fantadust [9677889@qq.com]
 * @date 2012-1-11 下午6:16:21
 */
public class KeyChest {
	
	private static final Map<Integer, KeyChest> commData = new HashMap<Integer, KeyChest>();
	/**
	 * 道具id
	 */
	private int goodsId;
	/**
	 * 钥匙id
	 */
	private int keyId;
	/**
	 * 名称
	 */
	private String name;
	/**
	 * 子物品名称
	 */
	private String nameList;
	/**
	 * 奖励道具id
	 */
	private String awardList;
	/**
	 * 奖励道具几率
	 */
	private String rateList;
	/**
	 * 道具id数组
	 */
	private int[] awards;
	/**
	 * 几率数组
	 */
	private int[] rates;
	public int getGoodsId() {
		return goodsId;
	}
	public void setGoodsId(int goodsId) {
		this.goodsId = goodsId;
	}
	public int getKeyId() {
		return keyId;
	}
	public void setKeyId(int keyId) {
		this.keyId = keyId;
	}
	public String getName() {
		return name;
	}
	public void setName(String name) {
		this.name = name;
	}
	public String getNameList() {
		return nameList;
	}
	public void setNameList(String nameList) {
		this.nameList = nameList;
	}
	public String getAwardList() {
		return awardList;
	}
	public void setAwardList(String awardList) {
		this.awardList = awardList;
	}
	public String getRateList() {
		return rateList;
	}
	public void setRateList(String rateList) {
		this.rateList = rateList;
	}
	public int[] getAwards() {
		return awards;
	}
	public int[] getRates() {
		return rates;
	}
	
	static{
		reload();
	}
	public static synchronized void reload(){
		List<KeyChest> chestList = XmlProcesser.processXml(KeyChest.class, ConstantsConfig.getLocaleResource()+"keyChest.xml");
		for (KeyChest e : chestList) {
			e.awards = StringProcesser.toIntArray(e.awardList);
			e.rates = StringProcesser.toIntArray(e.rateList);
			
			if (e.awards.length != e.rates.length) {
				LogUtil.getMain().error("KeyChest err "+e.goodsId);
			}
			commData.put(e.getGoodsId(), e);
		}		
	}
	
	public static KeyChest getKeyChest(int goodsId){
		return commData.get(goodsId);
	}
	
}
